﻿//===================================================================================
// $$
//
//
// Code By: Code Milker V2
// Date On: 2013//
//===================================================================================


namespace Forest.Lion.Data.SqlServer.Repositories
{
    using System;

    using System.Collections.Generic;

    using System.Data;

    using System.Linq;
    using Forest.Lion.Model;

    public class EducationRepository : BaseRepository, IEducationRepository
    {
        public EducationRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }
        public void Create(Education education)
        {
            this.GetDbSet<Education>().Add(education);
            this.UnitOfWork.SaveChanges();
        }

        public Education GetEducation(Guid educationId)
        {
            return this.GetDbSet<Education>()
                .Where(c => c.Id == educationId)
                .Single();
        }

        public void Update(Education updatedEducation)
        {
            this.GetDbSet<Education>().Attach(updatedEducation);
            this.SetEntityState(updatedEducation, updatedEducation.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid educationId)
        {
            Education educationToDelete = this.GetEducation(educationId);
            this.GetDbSet<Education>().Remove(educationToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IEnumerable<Education> Find()
        {
            return this.GetDbSet<Education>().Take(100)
                .ToList();
        }

        public IEnumerable<Education> GetAll()
        {
            return this.GetDbSet<Education>().Take(100)
                .ToList();
        }
    }
}
